package com.example.mybatis_book.mapper;

import com.example.mybatis_book.model.BookInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookInfoMapper {



    @Insert("INSERT INTO book_info (book_name,author,count,price,publish,status) values (" +
            "#{bookname},#{author},#{num},#{price},#{publisher},#{status})")
    Integer addBook(BookInfo bookInfo);

    @Results(id = "Mapper",value = {
            @Result(column = "book_name",property = "bookname"),
            @Result(column = "count",property = "num"),
            @Result(column = "publish",property = "publisher"),


    })
    @Select("SELECT * from book_info where status != 0  " +
            "order by id desc limit #{offset}, #{limit}")
    List<BookInfo> queryBookByPage(Integer offset, Integer limit);

    @Select("select count(1) from book_info where status != 0")
    Integer count();


    @ResultMap(value = "Mapper")
    @Select("select * from book_info where id = #{id}")
    BookInfo queryBookById(Integer id);


    Integer updateBookById(BookInfo bookInfo);


    Integer bathDeleteBook(List<Integer> ids);
}
